<script setup lang="ts">
import { ref } from "vue";
import { ModelHook } from "./utils/hook";
import { PureTableBar } from "@/components/RePureTableBar";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import Delete from "@iconify-icons/ep/delete";
import Search from "@iconify-icons/ep/search";
import Refresh from "@iconify-icons/ep/refresh";
import EditPen from "@iconify-icons/ep/edit-pen";
import AddFill from "@iconify-icons/ri/add-circle-line";
import getURL from "@/utils/http/address";
const formRef = ref();
const {
  form,
  columns,
  dataList,
  onSearch,
  loading,
  pagination,
  openDialog,
  handleDelete,
  handleSizeChange,
  handleCurrentChange,
  resetForm,
  sortChange
} = ModelHook();
import { useUserStoreHook } from "@/store/modules/user";

const userInfo = useUserStoreHook();
console.log("userInfo", userInfo);
</script>
<template>
  <div class="main">
    <el-form
      v-if="userInfo.comID == '1001'"
      ref="formRef"
      :inline="true"
      :model="form"
      class="search-form bg-bg_color w-[99/100] pl-8 pt-[12px]"
    >
      <el-form-item label="机构编码：" prop="comID">
        <el-input
          v-model="form.comID"
          placeholder="请输入机构编码"
          clearable
          class="!w-[200px]"
        />
      </el-form-item>
      <el-form-item label="机构名称" prop="comName">
        <el-input
          v-model="form.comName"
          placeholder="请输入机构名称"
          clearable
          class="!w-[180px]"
        />
      </el-form-item>
      <el-form-item label="机构类型" prop="comType">
        <el-select v-model="form.comType">
          <el-option value="个人">个人</el-option>
          <el-option value="团队">团队</el-option>
          <el-option value="企业">企业</el-option>
          <el-option value="政府">政府</el-option>
          <el-option value="事业单位">事业单位</el-option>
          <el-option value="其它">其它</el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="状态：" prop="disate">
        <el-select
          v-model="form.isFalg"
          placeholder="请选择状态"
          clearable
          class="!w-[180px]"
        >
          <el-option label="已启用" value="1" />
          <el-option label="已停用" value="0" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          :icon="useRenderIcon(Search)"
          :loading="loading"
          @click="onSearch"
        >
          搜索
        </el-button>
        <el-button :icon="useRenderIcon(Refresh)" @click="resetForm(formRef)">
          重置
        </el-button>
      </el-form-item>
    </el-form>
    <PureTableBar title="机构信息表" :columns="columns" @refresh="onSearch">
      <template v-if="userInfo.comID == '1001'" #buttons>
        <el-button
          type="primary"
          :icon="useRenderIcon(AddFill)"
          @click="openDialog()"
        >
          新增机构信息表
        </el-button>
      </template>
      <template v-slot="{ size }">
        <pure-table
          :pagination="pagination"
          :paginationSmall="size === 'small' ? true : false"
          @page-size-change="handleSizeChange"
          @page-current-change="handleCurrentChange"
          align-whole="center"
          showOverflowTooltip
          table-layout="auto"
          :loading="loading"
          @sort-change="sortChange"
          :size="size"
          adaptive
          :data="dataList"
          :columns="columns"
          :default-sort="{ prop: 'id', order: 'descending' }"
          :header-cell-style="{
            background: 'var(--el-fill-color-light)',
            color: 'var(--el-text-color-primary)'
          }"
        >
          <template #image="{ row }">
            <img :src="getURL + row.aiHead" style="width: 40px; margin: auto" />
          </template>
          <template #operation="{ row }">
            <el-button
              class="reset-margin"
              link
              type="primary"
              :size="size"
              :icon="useRenderIcon(EditPen)"
              @click="openDialog('编辑', row)"
            >
              修改
            </el-button>

            <el-popconfirm
              v-if="userInfo.comID == '1001'"
              :title="`是否删除机构：${row.tempName}`"
              @confirm="handleDelete(row)"
            >
              <template #reference>
                <el-button
                  class="reset-margin"
                  link
                  type="primary"
                  :size="size"
                  :icon="useRenderIcon(Delete)"
                >
                  删除
                </el-button>
              </template>
            </el-popconfirm>
          </template>
        </pure-table>
      </template>
    </PureTableBar>
  </div>
</template>
